<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>申请</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<jsp:include page="/scripts/common/index.html"></jsp:include>
<jsp:include page="/scripts/dhtmlx/index.html"></jsp:include>
<jsp:include page="/scripts/jquery/index.html"></jsp:include>
<jsp:include page="/scripts/bootstrap/index.html"></jsp:include>
<link rel="stylesheet" href="${basepath }style/default.css">
</head>
<script type="text/javascript">
	$(function() {
		$("#addCell").click(function() {
			addNewRow("1");
		});
		$("#deleteCell").click(function() {
			del(1);
		});
		$("#checkbox_all").click(function() {
			checkboxAll(document.getElementById("checkbox_all"));
		})
	});
	function save() {
		$.ajax({
				type : 'POST' ,
				url : '${basePath}page/model/WorkFlow/doAdd' ,
				data : $('#MyForm').serialize() ,
				dataType : "json" ,
				async : true ,
				cache : false ,
				jsonpCallback : "null" ,
				success : function(response, status, statusText) {
					//alert(response + ":" + status + ":" + statusText);
					if (response.status) {
						SN.alert.info("保存成功", function() {
							if (parent.query) {
								parent.query();
								closeWindow();
							}else{
								query();
							}
						});
					} else {
						alert(response.content);
						parent.query();
					}
				}
		});
	}
	function submit() {
		$.ajax({
				type : 'POST' ,
				url : '${basePath}page/model/WorkFlow/doSubmit' ,
				data : $('#MyForm').serialize() ,
				dataType : "json" ,
				async : true ,
				cache : false ,
				jsonpCallback : "null" ,
				success : function(response, status, statusText) {
					//alert(response + ":" + status + ":" + statusText);
					if (response.status) {
						SN.alert.info("提交成功", function() {
							if (parent.query) {
								parent.query();
								closeWindow();
							}
						});
					} else {
						
						alert(response.content);
						parent.query();
					}
				}
		});
	}
	function closeWindow() {
		parent.w1.close();
	}
	var row_count = 2; //因为页面已经有一行了，所以直接从2开始。
	function addNewRow(a) {
		var table1 = $("#time_table");
		var row = $("<tr></tr>");
		var td_1 = $("<td class='cellClass'></td>");
		var td_2 = $("<td></td>");
		var td_3 = $("<td></td>");
		var td_4 = $("<td></td>");
		var td_5 = $("<td align='center'></td>");
		td_1.append("<input type='checkbox' id='checkbox_"+row_count+"' name='checkbox'/>");
		td_2.append("<input type='text' class='form-control' id='name"+row_count+"'>");
		td_3.append("<select class='form-control' id='sex"+row_count+"'><option>男</option><option>女</option></select>");
		td_4.append("<input type='text' class='form-control' id='telphone"+row_count+"'>");
		td_5.append("<a href='#'>关联操作</a>");
		row.append(td_1);
		row.append(td_2);
		row.append(td_3);
		row.append(td_4);
		row.append(td_5);
		table1.append(row);
		row_count++;
	}
	function del(e) {
		var trNum = document.getElementById("time_table").children[0].children;
		for ( var i = 1; i < trNum.length; i++) {
			if (trNum[i].children[0].children[0].checked) {
				e = trNum[i].children[0].children[0].id.split("_")[1];
				//获取选中的复选框，然后循环遍历删除
				var ckbs = $("#checkbox_" + e + "");
				// 				ckbs.each(function() {
				$("#checkbox_" + e + "").parent().parent().remove();
				// 				});
			}
		}
		var trlenght = document.getElementById("time_table").children[0].children.length;
		if (trlenght < 2) {
			addNewRow(1);
		}
	}
</script>
<body>
	<form id="MyForm" name="MyForm">
		<table class="contTable">
			<tr class="firstTr">
				<td>
					<jsp:include page="/common/WF_Toolbar_New.jsp">
						<jsp:param name="save_func" value="save" />
						<jsp:param name="submit_func" value="submit" />
					</jsp:include>
				</td>
			</tr>
			<tr style="height:auto">
				<td valign="top">
					<div style="width:100%;height:300px;overflow-y:auto;">
						<div class="blockBorder">
							<strong>基本信息</strong>
							<div></div>
							<input id="guid" name="map.guid" type="hidden" class="form-control" value="${map.guid }">
							ApplyId
							<input id="ApplyId" readonly="readonly" name="map.ApplyId" type="text" class="form-control" value="${map.ApplyId }">
							rootCause:
							<input id="rootCause" name="map.rootCause" type="text" class="form-control" value="${map.rootCause }">
							applytype:
							<select id="applytype" name="map.applytype" type="text" class="form-control">
								<option value="">--请选择--</option>
								<option ${map.applytype eq '事假'?'selected=true':''  }>事假</option>
								<option ${map.applytype eq '年假'?'selected=true':''  }>年假</option>
							</select>
							<!-- 							<input id="applytype" name="map.applytype" type="text" class="form-control" value="${map.applytype }"> -->
							applyer:
							<input id="applyer" readonly="readonly" name="map.applyer" type="text" class="form-control" value="${map.applyer }">
							startTime:
							<input id="startTime" name="map.startTime" type="text" class="form-control Date" value="${map.startTime }">
							endTime:
							<input id="endTime" name="map.endTime" type="text" class="form-control Date" value="${map.endTime }">
							days:
							<input id="days" name="map.days" type="text" class="form-control" value="${map.days }">
						</div>
					</div>
				</td>
			</tr>
		</table>
	</form>
</body>
</html>
